//
//  TestAutoTextInputCell.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/11/25.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift
import RxSwift

// struct
class TestAutoTextInputCelllModel :  NSObject, TableCellConfigProtocol, BindKeyProtocol {
    var model: Any?
    
    required init(_ model: Any?) {
        self.model = model
    }

    func cellCls() -> UITableViewCell.Type {
        return TestAutoTextInputCell.self
    }
    
}

class TestAutoTextInputCell: UITableViewCell {

    @IBOutlet weak var tv: UITextView!
    
    let bag = DisposeBag()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        self.tv.rx.text.distinctUntilChanged().asObservable().subscribe { txt in
            guard let info = self.info as? TestAutoTextInputCelllModel else { return }
            info.postTableService(.updatesTable)
            info.postTableService(.toTableCellBottom)
        }.disposed(by: bag)

    }
    
    override func bindTo(_ info: Any?) {
        super.bindTo(info)
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
